package practice10;


import java.util.Iterator;
import java.util.List;

public class Teacher extends Person{
    private int id;
    private String name;
    private int age;
    private Klass klass;
    private List<Klass> classes;

    @Override
    public void setId(int id) {
        this.id = id;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    public Teacher(int id, String name, int age, List<Klass> classes) {
        super(id, name, age);
        this.classes = classes;
    }

    public Teacher(int id, String name, int age) {
        super(id, name, age);
    }

    public String introduce(){
        StringBuilder words = new StringBuilder(super.introduce() + " I am a Teacher.");
        if (this.classes != null) {
            words.append(" I teach Class");
            Iterator it = this.classes.iterator();
            while (it.hasNext()) {
                Klass klass = (Klass) it.next();
                words.append(String.format(" %d,", klass.getNumber()));
            }
            char[] items = words.toString().toCharArray();
            items[items.length - 1] = '.';
            words = new StringBuilder(new String(items));
        } else {
            words.append(" I teach No Class.");
        }
        return words.toString();
    }
    public Boolean isTeaching(Student student){
            return isIn(student);
    }
    public Boolean isIn(Student student){
        boolean v=false;
        for (Klass klass:classes){
            if (student.getKlass()==klass){
                v=true;
            }
        }
        return v;
    }

    public String introduceWith(Student student){
        boolean b=false;
        for (Klass klass:classes){
            if (klass.getNumber()==student.getKlass().getNumber()){
                b=true;
            }

        }
        if (b){
            return super.introduce()+" I am a Teacher. I teach "+student.getName()+".";
        }
        else {
            return super.introduce()+" I am a Teacher. I don't teach "+student.getName()+".";
        }
    }

    public Teacher(int id, String name, int age, Klass klass) {
        super(id, name, age);
        this.klass = klass;
    }

    @Override
    public void setAge(int age) {
        this.age = age;
    }

    public void setKlass(Klass klass) {
        this.klass = klass;
    }

    public List<Klass> getClasses() {
        return classes;
    }

    public void setClasses(List<Klass> classes) {
        this.classes = classes;
    }
    @Override
    public int getId() {
        return super.getId();
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public int getAge() {
        return super.getAge();
    }

    public Klass getKlass() {
        return klass;
    }
}
